package com.huaxia.controller.goOn;

import com.huaxia.pojo.goOn.BranchGoOn;
import com.huaxia.pojo.goOn.SaleDeptGoOn;
import com.huaxia.service.goOn.GoOnService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.context.WebApplicationContext;

import javax.servlet.ServletContext;
import java.util.List;

/**
 * @author wangli 爱我华夏，爱我中华！
 * @date 2020/06/10 17:21
 */
@RestController
@RequestMapping("/goOn")
public class GoOnController {

    @Autowired
    private WebApplicationContext webApplicationContext;
    @Autowired
    private GoOnService goOnService;


    @GetMapping("/getBranchGoOn13")
    public List<BranchGoOn> getBranchGoOn13(){
        ServletContext servletContext = webApplicationContext.getServletContext();
        List<BranchGoOn> branchGoOns = (List<BranchGoOn>) servletContext.getAttribute("branchGoOns13");
        if(branchGoOns==null){
            branchGoOns = goOnService.getBranchGoOn13();
            servletContext.setAttribute("branchGoOns13",branchGoOns);
            return branchGoOns;
        }
        return branchGoOns;
    }

    @GetMapping("/getBranchGoOn25")
    public List<BranchGoOn> getBranchGoOn25(){
        ServletContext servletContext = webApplicationContext.getServletContext();
        List<BranchGoOn> branchGoOns = (List<BranchGoOn>) servletContext.getAttribute("branchGoOns25");
        if(branchGoOns==null){
            branchGoOns = goOnService.getBranchGoOn25();
            servletContext.setAttribute("branchGoOns25",branchGoOns);
            return branchGoOns;
        }
        return branchGoOns;
    }

    @GetMapping("/getSaleDeptGoOn13")
    public List<SaleDeptGoOn> getsaleDeptGoOn13(){
        ServletContext servletContext = webApplicationContext.getServletContext();
        List<SaleDeptGoOn> saleDeptGoOns = (List<SaleDeptGoOn>) servletContext.getAttribute("saleDeptGoOns13");
        if(saleDeptGoOns==null){
            saleDeptGoOns = goOnService.getSaleDeptGoOn13();
            servletContext.setAttribute("saleDeptGoOns13",saleDeptGoOns);
            return saleDeptGoOns;
        }
        return saleDeptGoOns;
    }

    @GetMapping("/getSaleDeptGoOn25")
    public List<SaleDeptGoOn> getsaleDeptGoOn25(){
        ServletContext servletContext = webApplicationContext.getServletContext();
        List<SaleDeptGoOn> saleDeptGoOns = (List<SaleDeptGoOn>) servletContext.getAttribute("saleDeptGoOns25");
        if(saleDeptGoOns==null){
            saleDeptGoOns = goOnService.getSaleDeptGoOn25();
            servletContext.setAttribute("saleDeptGoOns25",saleDeptGoOns);
            return saleDeptGoOns;
        }
        return saleDeptGoOns;
    }
}
